import request from "@/utils/request"
import { createSlice } from "@reduxjs/toolkit"

export const user = createSlice({
  name: 'user',

  initialState: {
    info: {}
  },

  reducers: {
    setUser(preState, action) {
      preState.info = action.payload
    }
  }
})

export const { setUser } = user.actions

export const getUserAction = () => {
  return async (dispatch, getState) => {
    const { data: { data }} = await request.get('/user/profile')
    dispatch(setUser(data))
  }
}

export default user.reducer

